package bosc.cn.controller;

import bosc.cn.api.TransactionApi;
import bosc.cn.converter.transaction.TransactionStatusReqConverter;
import bosc.cn.converter.transaction.TransactionStatusResConverter;
import bosc.cn.dto.common.CommonResponse;
import bosc.cn.dto.common.RequestWrapper;
import bosc.cn.dto.common.ResponseWrapper;
import bosc.cn.dto.transaction.TransactionStatusReqDTO;
import bosc.cn.dto.transaction.TransactionStatusResDTO;
import bosc.cn.service.transaction.TransactionStatusService;
import bosc.cn.service.transaction.bo.TransactionStatusReqBO;
import bosc.cn.service.transaction.bo.TransactionStatusResBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wallet")
public class TransactionController implements TransactionApi {

    @Autowired
    private TransactionStatusService transactionStatusService;

    @PostMapping("/doQueryStatus")
    public ResponseWrapper<TransactionStatusResDTO> queryTransactionStatus(
            @RequestBody RequestWrapper<TransactionStatusReqDTO> reqWrapper) {

        // 获取 body
        TransactionStatusReqDTO body = reqWrapper.getBody();

        // DTO -> BO
        TransactionStatusReqBO reqBO = TransactionStatusReqConverter.toBO(body);

        // 调用 Service，返回 ResponseWrapper<TransactionStatusResBO>
        ResponseWrapper<TransactionStatusResBO> resWrapper = transactionStatusService.queryTransactionStatus(reqBO);

        // 从 Service 返回结果中取出 head 和 body
        CommonResponse head = resWrapper.getHead();
        TransactionStatusResBO resBO = resWrapper.getBody();

        // BO -> DTO
        TransactionStatusResDTO resDTO = TransactionStatusResConverter.toDTO(resBO);

        // 封装最终响应（head 原样传递，body 转换成 DTO）
        ResponseWrapper<TransactionStatusResDTO> responseWrapper = new ResponseWrapper<>();
        responseWrapper.setHead(head);
        responseWrapper.setBody(resDTO);

        return responseWrapper;

    }
}
